package com.jt.www.common.service.impl;

/**
 * @author admin_ltf
 * @create 2019-06-17 16:02
 */

import com.jt.www.common.service.EPolicyService;
import com.jt.www.dao.mapper.issue.mapper.IssuePolicyLogEntityMapper;
import com.jt.www.model.issue.entity.IssuePolicyLogEntity;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.weekend.Weekend;
import tk.mybatis.mapper.weekend.WeekendCriteria;

import java.util.List;

@Service
public class EPolicyServiceImpl implements EPolicyService {

    @Autowired
    private IssuePolicyLogEntityMapper issuePolicyLogEntityMapper;


    @Override
    public String updateEPolicyTimes(String appCode) {
        if (StringUtils.isBlank(appCode)) {
            return "投保单号不能为空!";
        }
        Weekend<IssuePolicyLogEntity> weekend = Weekend.of(IssuePolicyLogEntity.class);
        WeekendCriteria<IssuePolicyLogEntity, Object> criteria = weekend.weekendCriteria();
        //1电子保单
        criteria.andEqualTo(IssuePolicyLogEntity::getType, "1");
        criteria.andEqualTo(IssuePolicyLogEntity::getApplicationFormCode, appCode);
        List<IssuePolicyLogEntity> issuePolicyLogEntityList = issuePolicyLogEntityMapper.selectByExample(weekend);
        if (CollectionUtils.isEmpty(issuePolicyLogEntityList)) {
            return "没有电子保单相关信息";
        }
        //正常只会有一条记录
        IssuePolicyLogEntity issuePolicyLogEntity = issuePolicyLogEntityList.get(0);
        if (!"3".equals(issuePolicyLogEntity.getStatus())
                || 6 != issuePolicyLogEntity.getTimes()) {
            return "状态不是处理失败，不处理！";
        }
        IssuePolicyLogEntity update = new IssuePolicyLogEntity();
        update.setId(issuePolicyLogEntity.getId());
        update.setTimes(1);
        issuePolicyLogEntityMapper.updateByPrimaryKeySelective(update);

        return "成功";
    }
}
